﻿using LiteNetLib;
using LiteNetLib.Utils;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;

namespace Assets.Script.NetSystem.Battle.Core
{
    public class SocketCore
    {
        private NetManager netManager;
        public NetPeer peer;

        private int _frameTime=15;
        public int FrameTime { get { return _frameTime; } }

        public void Start(string ip,int port,string key,INetEventListener netEventListener)
        {
            netManager = new NetManager(netEventListener);
            netManager.Start();
            peer = netManager.Connect(ip, port, key);
            
        }
        public void Start(string ip,int port,NetDataWriter writer, INetEventListener netEventListener)
        {
            netManager = new NetManager(netEventListener);
            netManager.Start();
            peer = netManager.Connect(ip, port, writer);

        }

        /// <summary>
        /// update调用
        /// </summary>
        public void Poll()
        {
            netManager.PollEvents();
        }

        public void Stop()
        {
            if (netManager!=null)
            {
                netManager.Stop();
            }
        }


    }
}
